var initForm = function(){
	$('#_form_default').form({
		url :'sys/ClientBank/addOrUpdate',
		onBeforeLoad : function(param){
			$.messager.progress();
		},
		onLoadSuccess : function(data) {
			//加载完成之后才构建
			$.messager.progress("close");
		},
		onLoadError : function(data) {
			//加载完成之后才构建
			$.messager.progress("close");
			$.dialog.alert("加载内容失败,请重新刷新页面/联系管理员");
		},
		onSubmit : function(param) {
			if (!$(this).form("validate")) {
				$.dialog.alert("提交的选项中,有错误内容,请检查");
				return false;
			}
			$.messager.progress();
		},
		success : function(data) {	
			$.messager.progress("close");
			var jd = eval('(' + data + ')');
			if(!!!jd){
				$.dialog.alert("未知异常");
				return false;
			}
			if(jd.state!=200){
				$.dialog.alert(jd.message);
				return false;
			}
			var user = new Object();
			$.dialog({
				icon: 'success.gif',
				title: '提示',
			    content: '操作成功！',
			    ok: function(){
			        this.close();
			    },
			    close: function(){
			    	$('#enterprise').dataTable().fnDraw();
					clearFromData();
			    }
			});
			
		}
	});
};

var initDataTables = function(){
	$('#enterprise').dataTable({
		"bProcessing" : true, //DataTables载入数据时，是否显示‘进度’提示
        "bServerSide" : true, //是否启动服务器端数据导入
        "bStateSave" : false, //是否打开客户端状态记录功能,此功能在ajax刷新纪录的时候不会将个性化设定回复为初始化状态
        "bJQueryUI" : true, //是否使用 jQury的UI theme
       // "aLengthMenu" : [5, 10, 15], //更改显示记录数选项
       // "iDisplayLength" : 10, //默认显示的记录数
        "bAutoWidth" : true, //是否自适应宽度 update\
        "bScrollCollapse" : false, //是否开启DataTables的高度自适应，当数据条数不够分页数据条数的时候，插件高度是否随数据条数而改变
        "bPaginate" : false, //是否显示（应用）分页器
        "bInfo" : false, //是否显示页脚信息，DataTables插件左下角显示记录数
        "sPaginationType" : "full_numbers", //详细分页组，可以支持直接跳转到某页
        "bSort" : true, //是否启动各个字段的排序功能
        "aaSorting" : [[1, "DESC"]], //默认的排序方式，第3列，升序排列
        "bFilter" : false, //是否启动过滤、搜索功能
        "sScrollX": "100%",
		"sScrollXInner": 900,
        "sPaginationType": "full_numbers",
	    "sAjaxSource":"sys/ClientBank/list",
        "fnServerData":retrieveData,  //自定义数据获取函数
		"aoColumns" : [ {
			"mDataProp" : "id",
			"sTitle" : "操作",
			"sDefaultContent" : "",
			"sClass" : "center handletd",
			"sWidth":"100px",
			"mRender": function (data, display, row) {
				return top. _set_default_href(row.id);
				}
		},{
			"mDataProp" : "bankAccount",
			"sTitle" : "账户名",
			"bSortable": true,
			"sDefaultContent" : "",
			"sClass" : "center",
			"sWidth":"100px"
		}, {
			"mDataProp" : "bankType",
			"sTitle" : "银行卡类型",
			"bSortable": true,
			"sDefaultContent" : "",
			"sClass" : "center",
			"sWidth":"100px",
			"mRender": function (data, display, row) {
				return top.SYS_BASE_DATA['Client_Bank_Type_Code'][data];
				}
		},  {
			"mDataProp" : "bankName",
			"sTitle" : "银行名称",
			"bSortable": true,
			"sDefaultContent" : "",
			"sClass" : "center",
			"sWidth":"100px",
			"mRender": function (data, display, row) {
				return top.SYS_BASE_DATA['Client_Bank_Name_Code'][data];
				}
		},{
			"mDataProp" : "bankNumber",
			"sTitle" : "银行账户",
			"bSortable": true,
			"sDefaultContent" : "",
			"sClass" : "center",
			"sWidth":"100px"
		},
		 {
			"mDataProp" : "bankMainStatus",
			"sTitle" : "是否为主帐户",
			"bSortable": true,
			"sDefaultContent" : "",
			"sClass" : "center",
			"sWidth":"100px",
			"mRender": function (data, display, row) {
				return top.SYS_BASE_DATA['Client_Bank_Main_Status_Code'][data];
				}
		}
		],
		"oLanguage": {
            "sUrl":"static_resources/language/lang-cn.txt" //这个是国际化，也就是汉化的各种文字数据源，写对url就行了
        }
	});
};

var default_del = function(id){
	$.dialog.confirm('删除不可恢复，确定删除？', function(){
		$.ajax({
	       	url:'sys/ClientBank/delete',
	    	data:{pks:id},
	    	type:'post',
	    	dataType:'json',
	    	success:function(result){
	    	        if(result.state=="200"){
	    	        	$.dialog({
	    					icon: 'success.gif',
	    					title: '提示',
	    				    content: '删除成功！',
	    				    ok: function(){
	    				        this.close();
	    				    }
	    				});
	    	        	$('#enterprise').dataTable().fnDraw();
	    	        }else{
	    	        	$.dialog.alert('删除失败！');
	    	        }
	    		}
	        });
	}, function(){
	});
};


var default_edit = function(id){
	//parent._do_goto_right(parent.basePath+'jsp/sys/data_base_add_or_edit.jsp?id='+id);
	//修改电话调查信息
		var aData = $('#enterprise').dataTable().fnGetData();
		$.each(aData,function(index,node){
			if(node.id==id){
				$('#_form_default').form('load',node);
				return;
			}
		});
};

var initOther = function(){
	//新增
	$('li._class_btn_add').click(function(){
		clearFromData();
	});
};

var initSelect = function(){
	//初始化下拉框
	$('#bankType').mSelect({
		myClass:'easyui-validatebox',
		baseCode:'Client_Bank_Type_Code',
		isAllSelect:false,
		dataOptions:'required:true'
	});
	
	$('#bankName').mSelect({
		myClass:'easyui-validatebox',
		baseCode:'Client_Bank_Name_Code',
		isAllSelect:false,
		dataOptions:'required:true'
	});
	
	$('#bankMainStatus').mSelect({
		myClass:'easyui-validatebox',
		baseCode:'Client_Bank_Main_Status_Code',
		isAllSelect:false,
		dataOptions:'required:true'
	});
	
	
	
	
};


var clearFromData = function(){
	$("#_form_default").form()[0].reset();
	$("#myId").val(_param_id);
	$("#id").val("");
};

//自定义数据获取函数
function retrieveData( sSource, aoData, fnCallback ) {
	       aoData.push({name:'beanProxy[enable]',value:0});
	       aoData.push({name:'beanProxy[clientId]',value:_param_id});
	       aoData.push({name:'isNonPage',value:1});
	       aoData.push({name:'v2hldghlcib0agugzgf0ysbhy2nlc3m',value:1});
	        $.ajax( {
	                type: "POST", 
	                url: sSource, 
	                cache : false,
	                dataType : "json",
	                data : aoData, 
	                success: function(resp) {
	                	if(resp && resp.state == 200){
	                		fnCallback(resp.datagrid);
	                		return false;
	                	}
	                	fnCallback(null);
	            }
	        });
}


$(function(){
	initForm();
	initDataTables();
	initSelect();
	initOther();
	if(_is_not_empty(_param_id)){
		//$("#_form_default").form('load', 'sys/ClientHouse/find?clientId=' + _param_id);
	}
	$('input[name="confirm_button"]').click(function(){
		$('#_form_default').submit();
	});
	
});
